/** @jsxImportSource @emotion/react */
import * as React from "react";
import {Text,} from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, useItemInputControl,} from "../../common/base";
import {useMeasureInpFilter} from "../../common/hooks";
import {EachMeasureCritConfig} from "../../common/msCriteria";
import {useJudgmentEdit} from "../../hook/useJudgment";


export interface ObservationMeasureTourProps  extends InternalItemProps{
    label: string;
    config: ( (orc:any)=>EachMeasureCritConfig[][] ) | EachMeasureCritConfig[][];
    iAname?: string[];           //附加的存储那些字段     ，'观测备注'
    //插入的节点node相对偏移序号； 对useJudgmentEdit生成的nodes进行肢解的：
    inIdx: number;
    //在编辑器某一行的位置 插入node内容
    inNode: any;
}

const itemA观测1: never[]=[ ] ;
/**非正常的观测数据的表格；
 * 必须拆解前俩个，然后插入一句描述的： 需要一个node插入点的；
 * 【极其特殊】 中间一行 “b.连续20m路段坡度(用水平仪测量时填写在下列表格中）” 导致的混乱！ 需特殊化处理！ 加了参数：inNode
 * */
export const ObservationMeasureTourIn =
    React.forwardRef((
        {children, show, alone = true, refWidth,label,config,iAname,inIdx,inNode}: ObservationMeasureTourProps, ref
    ) => {
        const {inp, setInp} = useItemInputControl({ref});
        const newconfig=typeof config ==='function'? config(inp) : config;
        const {render,itemObservation, itemObservationA,}=useJudgmentEdit(inp,setInp, newconfig, false ,false);
        const itemA = React.useMemo(() => {
            return [...itemObservationA, ...itemA观测1, ...iAname??[]];
        }, [itemObservationA, iAname]);
        const [getInpFilter] = useMeasureInpFilter(itemObservation, itemA,);
        const [part1,partLeft] = React.useMemo(() => {
            const part1 = [...render.slice(0, inIdx)];
            const partLeft = [...render.slice(inIdx)];
            return [part1, partLeft];
        }, [render, inIdx]);
        return (
            <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                                 alone={alone} label={label}>
                <Text variant="h5">{label}：</Text>
                {part1}
                {inNode}
                {partLeft}
                {children}
            </InspectRecordLayout>
        );
    } );

